// src/api/business/cabinetStorage.ts
import { Alova } from '@/utils/http/alova/index';

// 器具箱存储信息数据结构
interface CabinetStorageInfo {
  id: string;
  cabinetId: string;
  shoeId?: string;
  shoeCode?: string;
  fastenerId?: string;
  fastenerCode?: string;
  position: number; // 位置编号
  state: number; // 状态: 0-空闲, 1-存放铁鞋, 2-存放紧固器
  createTime?: string;
  updateTime?: string;
}

const baseApi = '/web/eqCabinet/storage';

/**
 * 根据器具箱ID获取存储信息
 */
export function getCabinetStorageByCabinetId(params: { cabinetId: string }) {
  return Alova.Post<InResult<CabinetStorageInfo[]>>(
    baseApi + '/byCabinetId',
    { params },
    {
      isShowMessage: false,
    }
  );
}

export function getAccessRecordList(params: any) {
  return Alova.Post<InResult<CabinetStorageInfo[]>>(baseApi + '/accessRecordList', { params });
}

/**
 * 绑定设备到器具箱
 */
export function bindDeviceToCabinet(params: {
  cabinetId: string;
  position: number;
  shoeId?: string;
  fastenerId?: string;
}) {
  return Alova.Post<InResult<boolean>>(baseApi + '/binding', { params });
}

/**
 * 从器具箱解绑设备
 */
export function unbindDeviceFromCabinet(params: { cabinetId: string; position: number }) {
  return Alova.Post<InResult<boolean>>(baseApi + '/unBinding', { params });
}
